/**
 * Generali Solutions d'assurances - Tous droits rï¿½servï¿½s &copy; 2007 - 2010
 */
package fr.generali.accueilclient.resumesuspens.services.impl;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import fr.generali.accueilclient.commun.exception.AccueilClientBusinessException;
import fr.generali.accueilclient.resume.suspens.om.IResumeSuspens;
import fr.generali.accueilclient.resumesuspens.assembler.ResumeSuspensMapper;
import fr.generali.accueilclient.resumesuspens.services.IResumeSuspensService;
import fr.generali.souscriptiongestion.dommages.tosca.rechercheroperationscontratclient.services.IRechercherOperationsContratClientWebService;
import fr.generali.souscriptiongestion.dommages.tosca.rechercheroperationscontratclient.services.RessourcesIndisponiblesException;
import fr.generali.souscriptiongestion.dommages.tosca.rechercheroperationscontratclient.reponse.DTOReponse;

/**
 * @author ebrouillard
 */
@Service("resumeSuspensService")
public class ResumeSuspensService implements IResumeSuspensService {

    /**
     * LOGGER
     */
    private static final Logger LOGGER = LoggerFactory.getLogger(ResumeSuspensService.class);

    /**
     * Le service TOSCA de consultation des dossiers en instance
     */
    @Autowired
    private IRechercherOperationsContratClientWebService consultationOperationsContratClientService;

    /**
     * Appel du mapper ResumeSuspensMapper
     */
    @Autowired
    @Qualifier("resumeSuspensMapper")
    private ResumeSuspensMapper resumeSuspensMapper;

    /**
     * {@inheritDoc}
     */
    public IResumeSuspens rechercheSuspensIdClient(String idClient) throws AccueilClientBusinessException {
        LOGGER.info("Recherche des suspens");

        DTOReponse reponse = null;
        IResumeSuspens suspens = null;
        try {
            reponse =
                            consultationOperationsContratClientService
                                            .rechercherOperationsContratClient(resumeSuspensMapper
                                                            .mapperDTOPersonne(idClient));
            suspens = resumeSuspensMapper.mapperDTOReponse2Suspens(reponse);
        } catch (RessourcesIndisponiblesException e) {
            LOGGER.error("Erreur technique lors de l'appel au resume suspens TOSCA: '{}'.", e.getMessage());
            throw new AccueilClientBusinessException(e.getMessage(), e);
        }
        return suspens;
    }
}
